package com.hainatong.shiphelper.module.OAmgr.fragment;

import android.os.Bundle;
import com.base.common.view.widget.nineImageView.ImagesActivity;
import com.blankj.utilcode.util.StringUtils;
import com.google.android.material.snackbar.Snackbar;
import com.hainatong.shiphelper.mainhome.entity.MsgBean;
import com.hainatong.shiphelper.module.OAmgr.viewmodel.OAShenPiViewModel;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.FragmentOaBrokenApplyBinding;
import com.hainatong.shiphelper.utils.GsonUtil;
import com.hainatong.mvvmbase.base.BaseMvvmLazyFragment;

import android.util.Log;

public class OABrokenApplyFragment extends BaseMvvmLazyFragment<FragmentOaBrokenApplyBinding, OAShenPiViewModel>
{
    private static String OA_BROKEN_APPLY_TAG = "OABrokenApplyFragment";

    private MsgBean brokenMsg;

    public static OABrokenApplyFragment newInstance(String typeCode)
    {
        Bundle bundle = new Bundle();
        bundle.putString( OA_BROKEN_APPLY_TAG , typeCode );
        OABrokenApplyFragment fragment = new OABrokenApplyFragment();
        fragment.setArguments( bundle );
        return fragment;
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_oa_broken_apply;
    }

    @Override
    protected void initParameters()
    {
        Bundle args = getArguments();
        String type = "";
        if(  args != null )
        {
            type = args.getString(OA_BROKEN_APPLY_TAG , "");
        }

        if( !StringUtils.isEmpty( type ))
        {
            brokenMsg = GsonUtil.json2Obj( type, MsgBean.class );
        }
    }

    @Override
    protected void initViewBeforeLazyLoad()
    {
        viewDataBinding.btnAgree.setOnClickListener( view -> {
            /*
            User one = new User(3,"铂金",22,"棍",85);
            viewModel.saveUser( one )
                     .observe(getViewLifecycleOwner(),result ->{

                     });
                     */

        } );

        // 查看破损 图片
        viewDataBinding.rlBrokenImgs.setOnClickListener( v -> {

            Snackbar.make(viewDataBinding.getRoot(), "查看破损 图片", Snackbar.LENGTH_LONG).show();

            ImagesActivity.startActivity(getActivity(),"http://gank.io/images/f4f6d68bf30147e1bdd4ddbc6ad7c2a2");

            /*
            Rect bounds = new Rect();
            if (imageView != null)
            {
                ImageView thumbView = (ImageView) imageView;
                thumbView.getGlobalVisibleRect(bounds);
            }
            List<PreviewImageBean> previewImgList = computeBoundsBackward( bounds ,list);//组成数据
            PreviewBuilder.from((Activity) imageView.getContext())
                    .setImgs(previewImgList)
                    .setCurrentIndex(0)
                    //SettingSPUtils.getInstance().isUseCustomTheme() ? R.color.colorPrimary : R.color.xui_config_color_main_theme
                    .setProgressColor(R.color.colorPrimary )
                    .setType(PreviewBuilder.IndicatorType.Number)
                    .start();//启动
            */
        } );

    }

    @Override
    protected void onFragmentFirstVisible()
    {
        super.onFragmentFirstVisible();

        Log.e("OABrokenApplyFragment","onFragmentFirstVisible()方法开始");

        /*
        viewModel.getInfoByNet("LazyFragment的onFragmentFirstVisible")
                .observe(this,result ->{
                    viewModel.text.set( result );
                });
        */
        /*
        Observable.empty()
                  .timer(3000, TimeUnit.MICROSECONDS)
                  .compose(RxSchedulersUtils.Obs_io_main())
                  .doOnComplete(()->{
                  })
                  .subscribe();
        */

        //mLoadService.showSuccess();

    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {
    }
}
